import json

from django.shortcuts import render
from django.views import View
from django.http import JsonResponse
from rest_framework.views import APIView
from rest_framework.response import Response


# Create your views here.

class UserView(View):
    def get(self, request):
        data = {"name": "jk1998", "age": 18}
        res = JsonResponse(data)
        # res["Access-Control-Allow-Origin"] = "*"
        return res

class MaizuoView(View):
    def get(self, request):
        with open("js/maizuo.json", "r",encoding="utf-8") as f:
            res = json.load(f)
        res = JsonResponse(res)
        # res["Access-Control-Allow-Origin"] = "*"
        return res

class LoginView(APIView):
    def get(self, request):
        return Response({'name':"hjgwserfrfjyg", 'age':108})
    def post(self,request):
        print(request.META["HTTP_TOKEN"])
        username = request.data.get("username")
        password = request.data.get("password")
        if username == "jk1997" and password == "123456":
            return Response({"code":200,"msg":"登录成功"})
        else:
            return Response({"code":500,"msg":"登录失败"})

